<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Accessing Data in Pipelines | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'accessing-data-in-pipelines.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/accessing-data-in-pipelines.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/accessing-data-in-pipelines.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/accessing-data-in-pipelines.html" rel="nofollow" target="_blank">../en/accessing-data-in-pipelines.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="ingest.html">Ingest node</a></span>
»
<span class="breadcrumb-node">Accessing Data in Pipelines</span>
</div>
<div class="navheader">
<span class="prev">
<a href="pipeline.html">« Pipeline Definition</a>
</span>
<span class="next">
<a href="ingest-conditionals.html">Conditional Execution in Pipelines »</a>
</span>
</div>
<div class="chapter">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="accessing-data-in-pipelines"></a>Accessing Data in Pipelines<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ingest/ingest-node.asciidoc">edit</a>
</h2>
</div></div></div>
<p>The processors in a pipeline have read and write access to documents that pass through the pipeline.
The processors can access fields in the source of a document and the document’s metadata fields.</p>
<h3>
<a id="accessing-source-fields"></a>Accessing Fields in the Source<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ingest/ingest-node.asciidoc">edit</a>
</h3>
<p>Accessing a field in the source is straightforward. You simply refer to fields by
their name. For example:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "set": {
    "field": "my_field",
    "value": 582.1
  }
}</pre>
</div>
<p>On top of this, fields from the source are always accessible via the <code class="literal">_source</code> prefix:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "set": {
    "field": "_source.my_field",
    "value": 582.1
  }
}</pre>
</div>
<h3>
<a id="accessing-metadata-fields"></a>Accessing Metadata Fields<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ingest/ingest-node.asciidoc">edit</a>
</h3>
<p>You can access metadata fields in the same way that you access fields in the source. This
is possible because Elasticsearch doesn’t allow fields in the source that have the
same name as metadata fields.</p>
<p>The following example sets the <code class="literal">_id</code> metadata field of a document to <code class="literal">1</code>:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "set": {
    "field": "_id",
    "value": "1"
  }
}</pre>
</div>
<p>The following metadata fields are accessible by a processor: <code class="literal">_index</code>, <code class="literal">_type</code>, <code class="literal">_id</code>, <code class="literal">_routing</code>.</p>
<h3>
<a id="accessing-ingest-metadata"></a>Accessing Ingest Metadata Fields<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ingest/ingest-node.asciidoc">edit</a>
</h3>
<p>Beyond metadata fields and source fields, ingest also adds ingest metadata to the documents that it processes.
These metadata properties are accessible under the <code class="literal">_ingest</code> key. Currently ingest adds the ingest timestamp
under the <code class="literal">_ingest.timestamp</code> key of the ingest metadata. The ingest timestamp is the time when Elasticsearch
received the index or bulk request to pre-process the document.</p>
<p>Any processor can add ingest-related metadata during document processing. Ingest metadata is transient
and is lost after a document has been processed by the pipeline. Therefore, ingest metadata won’t be indexed.</p>
<p>The following example adds a field with the name <code class="literal">received</code>. The value is the ingest timestamp:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "set": {
    "field": "received",
    "value": "{{_ingest.timestamp}}"
  }
}</pre>
</div>
<p>Unlike Elasticsearch metadata fields, the ingest metadata field name <code class="literal">_ingest</code> can be used as a valid field name
in the source of a document. Use <code class="literal">_source._ingest</code> to refer to the field in the source document. Otherwise, <code class="literal">_ingest</code>
will be interpreted as an ingest metadata field.</p>
<h3>
<a id="accessing-template-fields"></a>Accessing Fields and Metafields in Templates<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ingest/ingest-node.asciidoc">edit</a>
</h3>
<p>A number of processor settings also support templating. Settings that support templating can have zero or more
template snippets. A template snippet begins with <code class="literal">{{</code> and ends with <code class="literal">}}</code>.
Accessing fields and metafields in templates is exactly the same as via regular processor field settings.</p>
<p>The following example adds a field named <code class="literal">field_c</code>. Its value is a concatenation of
the values of <code class="literal">field_a</code> and <code class="literal">field_b</code>.</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "set": {
    "field": "field_c",
    "value": "{{field_a}} {{field_b}}"
  }
}</pre>
</div>
<p>The following example uses the value of the <code class="literal">geoip.country_iso_code</code> field in the source
to set the index that the document will be indexed into:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "set": {
    "field": "_index",
    "value": "{{geoip.country_iso_code}}"
  }
}</pre>
</div>
<p>Dynamic field names are also supported. This example sets the field named after the
value of <code class="literal">service</code> to the value of the field <code class="literal">code</code>:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "set": {
    "field": "{{service}}",
    "value": "{{code}}"
  }
}</pre>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="pipeline.html">« Pipeline Definition</a>
</span>
<span class="next">
<a href="ingest-conditionals.html">Conditional Execution in Pipelines »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>